#ifndef _STRAWGUI_GUI_H_
#define _STRAWGUI_GUI_H_

#include "sConfig.h"
#include "sGuiObject.h"
#include "sLibrary.h"
#include "sEngine.h"
#include "sObserver.h"
#include <deque>

namespace sgui
{
namespace inst
{
	class sComponentInstance;
	class sComponentRectInstance;
    class sActionHandler;
};
namespace obs
{
    struct sMouseEvent;
};
class sGUI : public obs::sObserver
{
private:
	std::map<ID, sGUIObject*>					m_objects;
	std::deque<inst::sComponentInstance*>		m_instances;
	inst::sComponentRectInstance*				m_activeRect;
    inst::sActionHandler*                       m_handler;

	ID								registerGuiObject(sGUIObject *obj);
	void							refreshGuiObject(ID oldId, ID newId);
	void							unregisterGuiObject(ID id);

	friend sGUIObject;
public:
	sGUIObject*						getGuiObject(ID id) const;
private:
    CONTAINER_WRAPPER(sLibrary)     m_librarys;
    engine::sEngine*                m_engine;
public:
    CONTAINER_WRAPPER(sLibrary)&    getLibrarys();
    engine::sEngine&                getEngine();
    const engine::sEngine&          getEngine() const;
	inst::sComponentRectInstance*	getRectAt(const math::sPointf& point);

    std::deque<inst::sComponentInstance*>& getInstances();
    const std::deque<inst::sComponentInstance*>& getInstances() const;

	inst::sComponentInstance* addInstance(inst::sComponentInstance* instance);
    void setHandler(inst::sActionHandler *handler, const obs::sMouseEvent *event = NULL);
    void updataActiveRect(const obs::sMouseEvent &event);

	void draw();
	void update(double dt);
	
	bool OnEvent(const obs::sEvent& event);

	sGUI(engine::sEngine* engine);
	~sGUI();
};

};

#endif